package org.jeecg.modules.htxincailiao.order.domain.vo;

import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.htxincailiao.address.domain.vo.HTAddressVO;
import org.jeecg.modules.htxincailiao.payment.domain.vo.HTPaymentVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotNull;

@Data
public class HTOrderVO {
    private static final long serialVersionUID = 1L;

    /**主键ID*/
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键ID")
    private String id;
    /**父订单ID*/
    @Excel(name = "父订单ID", width = 15)
    @ApiModelProperty(value = "父订单ID")
    private String parentId;
    /**订单编号*/
    @Excel(name = "订单编号", width = 15)
    @ApiModelProperty(value = "订单编号")
    private String orderSn;
    /**买家ID*/
    @Excel(name = "买家ID", width = 15)
    @ApiModelProperty(value = "买家ID")
    private String buyerId;
    /**优惠券id*/
    @Excel(name = "优惠券id", width = 15)
    @ApiModelProperty(value = "优惠券id")
    private String couponId;
    /**支付ID*/
    @Excel(name = "支付ID", width = 15)
    @ApiModelProperty(value = "支付ID")
    private String paymentId;
    /**发货地址ID*/
    @Excel(name = "发货地址ID", width = 15)
    @ApiModelProperty(value = "发货地址ID")
    private String addressId;
    /**退款ID*/
    @Excel(name = "退款ID", width = 15)
    @ApiModelProperty(value = "退款ID")
    private String refundId;

    /**
     * 总商品数量
     */
    private Integer totalQuantity;
    /**商品总金额*/
    @Excel(name = "商品总金额", width = 15)
    @ApiModelProperty(value = "商品总金额")
    private java.math.BigDecimal totalAmount;
    /**优惠总金额*/
    @Excel(name = "优惠总金额", width = 15)
    @ApiModelProperty(value = "优惠总金额")
    private java.math.BigDecimal totalDiscountAmount;
    /**支付总金额*/
    @Excel(name = "支付总金额", width = 15)
    @ApiModelProperty(value = "支付总金额")
    private java.math.BigDecimal totalPaymentAmount;

    @ApiModelProperty(value = "总运费")
    private java.math.BigDecimal totalFreight;
    /**订单留言*/
    @Excel(name = "订单留言", width = 15)
    @ApiModelProperty(value = "订单留言")
    private String leaveMessage;
    /**是否拆分*/
    @Excel(name = "是否拆分", width = 15)
    @ApiModelProperty(value = "是否拆分")
    private Boolean isSplitted;
    /**订单状态：0-待付款、1-待发货、2-待收货、3-已完成、4-已取消*/
    @Excel(name = "订单状态：0-待付款、1-待发货、2-待收货、3-已完成、4-已取消", width = 15, dicCode = "order_status")
    @Dict(dicCode = "order_status")
    @ApiModelProperty(value = "订单状态：0-待付款、1-待发货、2-待收货、3-已完成、4-已取消")
    private Integer orderStatus;

    @ApiModelProperty(value = "订单状态描述：0-待付款、1-待发货、2-待收货、3-已完成、4-已取消")
    private String statusDescription;

    /**逻辑删除：1表示删除，0表示未删除。*/
    @Excel(name = "逻辑删除：1表示删除，0表示未删除。", width = 15)
    @ApiModelProperty(value = "逻辑删除：1表示删除，0表示未删除。")
    private Integer isDeleted;
    /**创建人*/
    @ApiModelProperty(value = "创建人")
    private String createBy;
    /**创建时间*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    private java.util.Date createTime;
    /**更新人*/
    @ApiModelProperty(value = "更新人")
    private String updateBy;
    /**更新时间*/
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    private java.util.Date updateTime;

    //订单类型: 0-商品订单 1-产业中心-会议订单家 2-产业中心-展会订单 3-产业中心-沙龙订单
    private Integer orderType;
    /**
     * 订单集合
     */
    private List<HTOrderVO> childOrderItems = Lists.newArrayList();

    /**
     * 店铺集合
     */
    private List<HTOrderShopVO> orderShopItems = Lists.newArrayList();

    private HTOrderShopVO orderShop;

    private HTAddressVO address;

    private HTPaymentVO payment;

    @NotNull(message = "支付描述不能为空")
    private String paymentDescription;

    private String expressEnterprise;

    private String expressSn;

    private String expressSearchUrl;

    //订单状态描述：0-待付款、1-待发货、2-待收货、3-已完成、4-已取消
    public void setOrderStatus(Integer orderStatus) {
        switch (orderStatus){
            case 0:
                setStatusDescription("待付款");
                break;
            case 1:
                setStatusDescription("待发货");
                break;
            case 2:
                setStatusDescription("待收货");
                break;
            case 3:
                setStatusDescription("已完成");
                break;
            case 4:
                setStatusDescription("已取消");
                break;
            default:
                break;
        }
        this.orderStatus = orderStatus;
    }


//
//    /**
//     * 订单会议信息
//     * */
//    private HTOrderMeeting orderMeeting;
//
//    /**
//     *订单沙龙信息
//     */
//    private HTOrderSalon orderSalon;

    /**
     *订单产业服务信息（会议、会展、沙龙）
     *
     */
    private HTOrderIndustryVO orderIndustry;



    private boolean hasLibraryArchives;
    private boolean hasReportArchives;

    public Boolean getHasLibraryArchives() {
        boolean hasLibraryArchives = false;
        if(oConvertUtils.isNotEmpty(orderShopItems) && !orderShopItems.isEmpty()) {
            for (HTOrderShopVO orderShop :  orderShopItems) {

                List<HTOrderProductVO> orderProductItems = orderShop.getOrderProductItems();
                if(oConvertUtils.isNotEmpty(orderProductItems) && !orderProductItems.isEmpty()) {
                    for (HTOrderProductVO orderProduct :  orderShop.getOrderProductItems()) {
                        if (oConvertUtils.isNotEmpty(orderProduct.getLibraryId()))
                        hasLibraryArchives = true;
                        break;
                    }
                }

                if (hasLibraryArchives) break;
            }
        }

        return hasLibraryArchives;
    }


    public Boolean getHasReportArchives() {
        boolean hasReportArchives = false;
        if(oConvertUtils.isNotEmpty(orderShopItems) && !orderShopItems.isEmpty()) {
            for (HTOrderShopVO orderShop :  orderShopItems) {

                List<HTOrderProductVO> orderProductItems = orderShop.getOrderProductItems();
                if(oConvertUtils.isNotEmpty(orderProductItems) && !orderProductItems.isEmpty()) {
                    for (HTOrderProductVO orderProduct :  orderShop.getOrderProductItems()) {
                        if (oConvertUtils.isNotEmpty(orderProduct.getReportId()))
                            hasReportArchives = true;
                        break;
                    }
                }

                if (hasReportArchives) break;
            }
        }

        return hasReportArchives;
    }

}
